'use strict';
var moment = require('moment');
exports = module.exports = function($scope,$rootScope,$timeout,$http,$state,$location,$window) {
    //默认当天
    $scope.onedate = moment().format('YYYY-MM-DD');
    //默认选择全部用户
    $scope.UserID='all';
    $scope.customerlist = select2Config( [] );
    $scope.showFlag = true;
    $scope.obj = {};
    //搜索逻辑
    $scope.search=function(){
        $scope.getSurvey();
        $scope.getOnline();
        $scope.getGenre();
        $scope.getShowad();
        $scope.getCloud();
        $scope.getB2();
        $scope.getDler();
        $scope.flagChange();
        $scope.UserID=="all"?$scope.showFlag=true:$scope.showFlag=false;//显示在线终端数和总开机次数
    };
    //判断在线终端数
    $scope.busiFlag = true;
    $scope.flagChange = function(){
        var today = moment().format('YYYY-MM-DD');
        $scope.busiFlag = ( $scope.UserID=="all" && $scope.onedate==today )
    };
    //1.概况
    $scope.getSurvey = function(){
        $scope.survey = {"Terminals":382630,"macs":null,"BootCount":921837,"BootDuration":2071161.5}
    }
    //在线终端数
    $scope.getOnline = function(){
        var data = "\"0,0\"".replace(/\"/g,"").split(",");
        $scope.online = data[0];
        $scope.CloudOnline = data[1];
    }
    //2.导航（搜狗导航、2345导航）
    $scope.getGenre = function(){
        $scope.obj.nav = [{"CountTime":"2018-03-14 00:00:00","ADID":1,"ADName":"搜狗导航","BootCount":30596,"Lock":53269},{"CountTime":"2018-03-14 00:00:00","ADID":2,"ADName":"2345导航","BootCount":44671,"Lock":42648}]
    }
    //3.DSP广告
    $scope.getShowad = function(){
        $scope.obj.showad = [{"CountTime":"2018-03-14 00:00:00","BusinessID":102,"Name":"桌标","terminals":1459,"request":0,"Impression":9786,"click":55,"sort":0},{"CountTime":"2018-03-14 00:00:00","BusinessID":1031,"Name":"前台如意弹","terminals":7357,"request":0,"Impression":5495,"click":631,"sort":1},{"CountTime":"2018-03-14 00:00:00","BusinessID":1032,"Name":"后台如意弹","terminals":344123,"request":0,"Impression":36216329,"click":496733,"sort":2},{"CountTime":"2018-03-14 00:00:00","BusinessID":101,"Name":"矩阵","terminals":13117,"request":81499,"Impression":0,"click":0,"sort":3},{"CountTime":"2018-03-14 00:00:00","BusinessID":110,"Name":"后台矩阵","terminals":292912,"request":38991916,"Impression":0,"click":0,"sort":4},{"CountTime":"2018-03-14 00:00:00","BusinessID":104,"Name":"英雄宝库","terminals":2925,"request":7429,"Impression":0,"click":0,"sort":5}]
    }
    //4.智能元
    $scope.getCloud = function(){
        $scope.obj.cloud = {"CountTime":"2018-03-14","Terminals":151793,"CPU":704018,"GPU":33549}
    }
    //5.SKP
    $scope.getB2 = function(){
        $scope.obj.b2 = {"CountTime":"2018-03-14","Terminals":332352,"BusinessID":129,"Action":77815,"CNZZUV":null}
    }
    //6.TD
    $scope.getDler = function(){
        $scope.obj.dler = {"CountTime":"2018-03-14","Terminals":0,"BusinessID":128,"Downloads":2823,"CNZZUV":null}
    }
    //初始化init
    $scope.search();
    //优化代码
    function getOption(url){
        var x={
            "begin":$scope.onedate,
            "UserID":$scope.UserID,
        };
        if($scope.UserID=="all") {x.UserID = "";}
        var option = {
            method:'GET',
            url:url,
            params:x
        }
        return option;
    }
    //跳转
    $scope.jump_page = function(name){
        var arr = {
            "桌标":"desktop",
            "前台矩阵":"adrpt",
            "矩阵":"adrpt",
            "后台矩阵":"adrpt",
            "前台如意弹":"adrpt",
            "后台如意弹":"adrpt",
            "如意弹":"adrpt",
            "开机右下角":"adrpt",
            "QQBanner":"qqad",
            "QQ擎天柱":"qqad",
            "QQ文字":"qqad",
        }
        console.log(arr[name]+"**"+name);
        if(arr[name]){
            $state.go('rpt.'+arr[name],{mainParam:name});
        }
    }
    $scope.jump = function(name,businessName){
        console.log('rpt.'+name,option);
    }
    $scope.getClass = function(name){
        var arr = {
            "桌标":"icon01",
            "矩阵":"icon02",
            "前台矩阵":"icon02",
            "后台矩阵":"icon03",
            "前台如意弹":"icon04",
            "后台如意弹":"icon05",
            "如意弹":"icon05",
            "开机右下角":"icon06",
            "QQBanner":"icon07",
            "QQ擎天柱":"icon08",
            "QQ文字":"icon09"
        }
        return arr[name];
    }
    $scope.getName0 = function(name){
        var arr = [ "桌标", "前台如意弹", "后台如意弹", "QQBanner", "QQ擎天柱" ]
        return arr.indexOf(name) > -1;
    }
    $scope.getName1 = function(name){
        var arr = [ "后台矩阵", "矩阵", "开机右下角" ]
        return arr.indexOf(name) > -1;
    }
    $scope.getName2 = function(name){
        var arr = [ "桌标", "前台如意弹", "后台如意弹", "QQBanner", "QQ擎天柱", "后台矩阵", "矩阵", "开机右下角", "英雄宝库" ]
        return arr.indexOf(name) >-1;
    }
    $scope.getSrc = function(name){
        var arr = {
            "搜狗导航":"",
            "2345导航":"",
            "备用导航":"",
        }
        if(arr[name]==undefined){
            return "img/"+name+".jpg";
        }
        return arr[name];
    }
}